home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / MacApp Release 10 / MacApp Release 10 - HD Ready / Libraries / Views / Sources / UMenuView.cp < prev    next >
Encoding:
Text File  |  1996-04-03  |  22.5 KB  |  837 lines  |  [TEXT/MPS ]

  1. //----------------------------------------------------------------------------------------
  2. // UMenuView.cp 
  3. // Copyright © 1984-96 by Apple Computer, Inc. All rights reserved.
  4. //----------------------------------------------------------------------------------------
  5.  
  6. #ifndef __UMENUVIEW__
  7. #include "UMenuView.h"
  8. #endif
  9.  
  10. // MacApp
  11.  
  12. //    #ifndef __UAPPLICATION__
  13. //    #include "UApplication.h"
  14. //    #endif
  15.  
  16. #ifndef __UCOMMAND__
  17. #include "UCommand.h"
  18. #endif
  19.  
  20. #ifndef __UDEBUG__
  21. #include "UDebug.h"
  22. #endif
  23.  
  24. #ifndef __UDISPATCHER__
  25. #include "UDispatcher.h"
  26. #endif
  27.  
  28. #ifndef __UDOCUMENT__
  29. #include "UDocument.h"
  30. #endif
  31.  
  32. #ifndef __UEVENT__
  33. #include "UEvent.h"
  34. #endif
  35.  
  36. #ifndef __UFAILURE__
  37. #include "UFailure.h"
  38. #endif
  39.  
  40. #ifndef __UGEOMETRY__
  41. #include "UGeometry.h"
  42. #endif
  43.  
  44. #ifndef __ULIST__
  45. #include "UList.h"
  46. #endif
  47.  
  48. #ifndef __UMACAPPGLOBALS__
  49. #include "UMacAppGlobals.h"
  50. #endif
  51.  
  52. #ifndef __UMACAPPUTILITIES__
  53. #include "UMacAppUtilities.h"
  54. #endif
  55.  
  56. #ifndef __UMEMORY__
  57. #include "UMemory.h"
  58. #endif
  59.  
  60. #ifndef __UMENUMGR__
  61. #include "UMenuMgr.h"
  62. #endif
  63.  
  64. #ifndef __UPATCH__
  65. #include "UPatch.h"
  66. #endif
  67.  
  68. // Toolbox
  69.  
  70. #ifndef __DIALOGS__
  71. #include <Dialogs.h>
  72. #endif
  73.  
  74. #ifndef __EDITIONS__
  75. #include <Editions.h>
  76. #endif
  77.  
  78. #ifndef __ERRORS__
  79. #include <Errors.h>
  80. #endif
  81.  
  82. #ifndef __TOOLUTILS__
  83. #include <ToolUtils.h>
  84. #endif
  85.  
  86. // ANSI
  87.  
  88. #if qDebugMsg
  89.     #ifndef __STDIO__
  90.     #include <stdio.h>
  91.     #endif
  92. #endif
  93.  
  94. //----------------------------------------------------------------------------------------
  95. Boolean gTrackingInMenu;
  96.  
  97. //----------------------------------------------------------------------------------------
  98. struct MenuRec
  99. {
  100.     ResNumber mID;
  101.     TMenuView* mObject;
  102. };
  103.  
  104.  
  105. typedef MenuRec MenuArray[4000];
  106. typedef MenuRec* MenuArrayPtr;
  107. typedef MenuRec** MenuArrayHandle;
  108.  
  109. //----------------------------------------------------------------------------------------
  110. static CGrafPort pMenuCPort;                // Color port for compatibility. Private
  111.                                             // grafPort used to focus the menu w/ o messing
  112.                                             // up the Window Manager port.
  113. static MenuArrayHandle pMenuArray;            // Used to map a MenuRef to the TMenuView
  114. static ResNumber pNumMenus;
  115. static Handle pCustDefproc;                    // Replaces the menu's menuProc field 
  116.  
  117.  
  118. //========================================================================================
  119. // GLOBAL Procedures
  120. //========================================================================================
  121. static long Future(long delta);
  122. static void WaitTickChange();
  123. static TMenuView* FindTMenuView(MenuRef theMenu);
  124. static pascal void MenuDefproc(short message,
  125.                                MenuRef theMenu,
  126.                                CRect& menuRect,
  127.                                Point hitPt, // CW 5.5 thinks address is passed in if this is a CPoint!
  128.                                short& whichItem);
  129.  
  130. #undef Inherited
  131.  
  132. //----------------------------------------------------------------------------------------
  133. // Future: Returns the TickCount some time in the future. 
  134. //----------------------------------------------------------------------------------------
  135. long Future(long delta)
  136. {
  137.     return TickCount() + delta;
  138. } // Future 
  139.  
  140. //----------------------------------------------------------------------------------------
  141. // WaitTickChange: 
  142. //----------------------------------------------------------------------------------------
  143. #pragma segment MAMenuRes
  144.  
  145. void WaitTickChange()
  146. {
  147.     long now = TickCount();
  148.     while (TickCount() != now)
  149.         ;
  150. } // WaitTickChange 
  151.  
  152. //----------------------------------------------------------------------------------------
  153. // FindTMenuView: 
  154. //----------------------------------------------------------------------------------------
  155. #pragma segment MAMenuRes
  156.  
  157. TMenuView* FindTMenuView(MenuRef theMenu)
  158. {
  159.     MenuArrayPtr p = *pMenuArray;
  160.     ResNumber id = (*theMenu)->menuID;
  161.  
  162.     for (ResNumber i = 0; i < pNumMenus; ++i)
  163.         if (p[i].mID == id)
  164.             return p[i].mObject;
  165.     return NULL;
  166. } // FindTMenuView 
  167.  
  168. //----------------------------------------------------------------------------------------
  169. // MenuDefproc: Called by the MDEF resource. 
  170. //----------------------------------------------------------------------------------------
  171. #pragma segment MAMenuRes
  172.  
  173. pascal void MenuDefproc(short message,
  174.                         MenuRef theMenu,
  175.                         CRect& menuRect,
  176.                         Point hitPt, // CW 5.5 thinks address is passed in if this is a CPoint!
  177.                         short& whichItem)
  178.  
  179. {
  180.     long OldA5 = SetCurrentA5();                // ***** Called from trap patches *****
  181.     
  182.     
  183.     TMenuView * menuObj = FindTMenuView(theMenu);
  184.  
  185.     if (menuObj != NULL)
  186.     {
  187.         CPoint fixedHitPt(hitPt);
  188.         if (message == mPopUpMsg)
  189.         {    // The hitPt is not a point; its coordinates are switched (see TN#172).
  190.             fixedHitPt.h = hitPt.v;
  191.             fixedHitPt.v = hitPt.h;
  192.         }
  193.     
  194.         // Dispatch to the TMenuView object 
  195.         menuObj->HandleDefproc(message, theMenu, menuRect, fixedHitPt, whichItem);
  196.     }
  197. #if qDebug
  198.     else
  199.         ProgramBreak("MenuDefproc called with no TMenuView object");
  200. #endif
  201.     
  202.     SetA5(OldA5);
  203. } // MenuDefproc 
  204.  
  205. //----------------------------------------------------------------------------------------
  206. // InitUMenuView: 
  207. //----------------------------------------------------------------------------------------
  208. #pragma segment MAMenuInit
  209.  
  210. void InitUMenuView()
  211.  
  212. {
  213.     if (qNeedsColorQD || HasColorQD())
  214.         OpenCPort(&pMenuCPort);
  215.     else
  216.         OpenPort((GrafPtr) & pMenuCPort);
  217.     
  218.     pNumMenus = 0;
  219.     pMenuArray = (MenuArrayHandle) NewPermHandle(0);
  220.  
  221. #if qPowerPC
  222.     RoutineDescriptorHandle h =
  223.         (RoutineDescriptorHandle)NewPermHandle(sizeof(RoutineDescriptor));
  224.     
  225.     RoutineDescriptor aMDEFUPP = BUILD_ROUTINE_DESCRIPTOR(uppMenuDefProcInfo,MenuDefproc);
  226.     
  227.     ::BlockMove(&aMDEFUPP, *h, sizeof(RoutineDescriptor)); // leave BlockMove so cache flushes
  228. #else
  229.     JmpInstructionTemplate** h =
  230.         (JmpInstructionTemplate**) NewPermHandle(sizeof(JmpInstructionTemplate));
  231.     PatchJmpInstruction(*h, (void*)StripLong(MenuDefproc));
  232. #endif
  233.     
  234.     pCustDefproc = (Handle) h;
  235. } // InitUMenuView 
  236.  
  237.  
  238. //========================================================================================
  239. // CLASS TMenuView
  240. //========================================================================================
  241. #undef Inherited
  242. #define Inherited TView
  243.  
  244. #pragma segment MAMenuInit
  245. MA_DEFINE_CLASS_M1(TMenuView, Inherited);
  246.  
  247. //----------------------------------------------------------------------------------------
  248. // TMenuView constructor
  249. //----------------------------------------------------------------------------------------
  250. #pragma segment MAMenuInit
  251.  
  252. TMenuView::TMenuView()
  253. {
  254.     fBorder = gZeroRect;
  255.     fFlashInterval = -1;
  256.     fHighlighted = FALSE;
  257.     fMenuRef = NULL;
  258.     fNextFlash = 0;
  259. } // TMenuView::TMenuView
  260.  
  261. //----------------------------------------------------------------------------------------
  262. // TMenuView destructor
  263. //----------------------------------------------------------------------------------------
  264. #pragma segment MADestructorRes
  265.  
  266. TMenuView::~TMenuView()
  267. {
  268. }
  269.  
  270. //----------------------------------------------------------------------------------------
  271. // TMenuView::IMenuView: 
  272. //----------------------------------------------------------------------------------------
  273. #pragma segment MAMenuInit
  274.  
  275. void TMenuView::IMenuView(ResNumber rsrcID,
  276.                                  short menuWidth,
  277.                                  short menuHeight)
  278.  
  279. {
  280.     VPoint itsSize(menuWidth, menuHeight);
  281.  
  282.     // Initialize fields 
  283.     this->IView(NULL, NULL, gZeroVPt, itsSize, sizeVariable, sizeVariable);
  284.     fNextHandler = gDispatcher;                // so postcommand flows to the app 
  285.  
  286.     if (rsrcID != kNoResource)
  287.     {
  288.         MAVolatile(MenuRef, m);
  289. #if qDebugMsg
  290.         MAVolatileInit(ResNumber, volatileRsrcID, rsrcID);
  291. #endif
  292.  
  293.         FailInfo fi;
  294.         Try(fi)
  295.         {
  296.             // Read in menu and set its defproc 
  297.             m = MAGetMenu(rsrcID);
  298.             FailNILResource((Handle)m);
  299.     
  300.             SetPermHandleSize((Handle) pMenuArray, sizeof(MenuRec) * (pNumMenus + 1));
  301.             ++pNumMenus;
  302.             fi.Success();
  303.         }
  304.         else
  305.         {
  306.             if (!m)
  307.             {    // FailNILResource failed
  308. #if qDebugMsg
  309.                 char msg[128];
  310.                 
  311.                 sprintf(msg, "No such Menu! (rsrcID = %4s)", (char *) &volatileRsrcID);
  312.                 ProgramBreak(msg);
  313. #endif
  314.             }
  315.             this->Free();
  316.             fi.ReSignal();
  317.         }
  318.         (*pMenuArray)[pNumMenus-1].mID = (*m)->menuID;
  319.         (*pMenuArray)[pNumMenus-1].mObject = this;
  320.  
  321.         (*m)->menuProc = pCustDefproc;
  322.         fMenuRef = m;
  323.  
  324.         short item = 0;
  325.         CRect itsRect(gZeroRect);
  326.         MenuDefproc(mSizeMsg, m, itsRect, gZeroPt, item);// recompute the menu size 
  327.     }
  328. } // TMenuView::IMenuView 
  329.  
  330. //----------------------------------------------------------------------------------------
  331. // TMenuView::FindItem: 
  332. //----------------------------------------------------------------------------------------
  333. #pragma segment MAMenuNever
  334.  
  335. short TMenuView::FindItem(CPoint)
  336.  
  337. {
  338.     return 0;
  339. } // TMenuView::FindItem 
  340.  
  341. //----------------------------------------------------------------------------------------
  342. // TMenuView::HandleDefproc: 
  343. //----------------------------------------------------------------------------------------
  344. #pragma segment MAMenuRes
  345.  
  346. void TMenuView::HandleDefproc(short message,
  347.                                      MenuRef theMenu,
  348.                                      CRect& menuRect,
  349.                                      CPoint hitPt,
  350.                                      short& whichItem)
  351.  
  352. {
  353.     GrafPtr savePort;
  354.     
  355.     // Save the wmgr port && set our private port 
  356.     GetPort(&savePort);
  357.  
  358.     SetPort((GrafPtr) & pMenuCPort);
  359.     // Match the location and size that the menu mgr gives us 
  360.     if ((message == mDrawMsg) || (message == mChooseMsg))
  361.     {
  362.         MovePortTo(menuRect.left, menuRect.top);
  363.         PortSize(menuRect.GetLength(hSel), menuRect.GetLength(vSel));
  364.         fLocation = menuRect[topLeft];
  365.     }
  366.  
  367.     this->InvalidateCoordinates();
  368.     if (this->Focus())
  369.     {
  370.         GlobalToLocal(hitPt);
  371.         GlobalToLocal(menuRect[topLeft]);
  372.         GlobalToLocal(menuRect[botRight]);
  373.  
  374.         this->SetEnable((((*theMenu)->enableFlags) & 1) != 0);
  375.         switch (message)
  376.         {
  377.             case mDrawMsg:
  378. #if qDebugMsg
  379.                 if (gIntenseDebugging)
  380.                     fprintf(stderr, "mDrawMsg\n");
  381. #endif
  382.  
  383.                 this->HandleDrawMessage(message, theMenu, menuRect, hitPt, whichItem);
  384.                 break;
  385.                     
  386.             case mChooseMsg:
  387. #if qDebugMsg
  388.                 if (gIntenseDebugging)
  389.                     fprintf(stderr, "mChooseMsg\n");
  390. #endif
  391.  
  392.                 this->HandleChooseMessage(message, theMenu, menuRect, hitPt, whichItem);
  393.                 break;
  394.                     
  395.             case mSizeMsg:
  396. #if qDebugMsg
  397.                 if (gIntenseDebugging)
  398.                     fprintf(stderr, "mSizeMsg\n");
  399. #endif
  400.  
  401.                 this->HandleSizeMessage(message, theMenu, menuRect, hitPt, whichItem);
  402.                 break;
  403.                     
  404.             case mPopUpMsg:
  405. #if qDebugMsg
  406.                 if (gIntenseDebugging)
  407.                     fprintf(stderr, "mPopUpMsg\n");
  408. #endif
  409.  
  410.                 this->HandlePopUpMessage(message, theMenu, menuRect, hitPt, whichItem);
  411.                 break;
  412.  
  413. #if qDebugMsg
  414.             default:
  415.                 if (gIntenseDebugging)
  416.                     fprintf(stderr, "otherwise message\n");
  417.                 break;
  418. #endif
  419.  
  420.         }
  421.  
  422.         LocalToGlobal(menuRect[topLeft]);
  423.         LocalToGlobal(menuRect[botRight]);
  424.  
  425.         this->InvalidateFocus();
  426.     }
  427.  
  428.     SetPort(savePort);
  429. } // TMenuView::HandleDefproc 
  430.  
  431. //----------------------------------------------------------------------------------------
  432. // TMenuView::HandleChooseMessage: 
  433. //----------------------------------------------------------------------------------------
  434. #pragma segment MAMenuRes
  435.  
  436. void TMenuView::HandleChooseMessage(short /* message */,
  437.                                            MenuRef /* theMenu */,
  438.                                            CRect& /* menuRect */,
  439.                                            CPoint hitPt,
  440.                                            short& whichItem)
  441.  
  442. {
  443.     short newItem = kNoMenuItem;
  444.     Boolean saveTrackingInMenu = gTrackingInMenu;
  445.  
  446.     // so that trackers get a chance to know that they're tracking in menus 
  447.     gTrackingInMenu = TRUE;
  448.  
  449.     if (this->IsEnabled())                            // menu enabled 
  450.     {
  451.         // see if CPoint is within hit area 
  452.         CRect hitRect = this->GetQDExtent() + fBorder;
  453.  
  454.         if (hitRect.Contains(hitPt))            // in menu (not border) 
  455.         {
  456.             Boolean oldObjectPerm;
  457.             TToolboxEvent * event = NULL;
  458.             EventRecord theEventRecord;
  459.  
  460.             // NOTE: Either your subclass of TTearOffMenu should override DoMouseCommand
  461.             // or one of TTearOffMenu's view's subview's should override DoMouseCommand so
  462.             // that it creates and posts a TTracker. TTearOffMenu's override of
  463.             // PostCommand will ensure that the tracker is tracked immediately. The
  464.             // tracker, having been posted and tracked, will then get executed next time
  465.             // PerformCommand is called. So, when we're done with HandleMouseDown below,
  466.             // we simply tell the menu manager that no menu item was selected, ie
  467.             // newItem == kNoMenuItem.
  468.  
  469.             theEventRecord.what = mouseDown;
  470.             theEventRecord.message = 0;
  471.             theEventRecord.when = TickCount();
  472.             theEventRecord.where = hitPt;
  473.             theEventRecord.modifiers = 0;
  474.             
  475.             if (Button())
  476.                 theEventRecord.modifiers |= btnState;
  477.                 
  478.             if (IsCommandKeyDown())
  479.                 theEventRecord.modifiers |= cmdKey;
  480.                 
  481.             if (IsOptionKeyDown())
  482.                 theEventRecord.modifiers |= optionKey;
  483.                 
  484.             oldObjectPerm = AllocateObjectsFromPerm(FALSE);
  485.             event = new TToolboxEvent;
  486.             AllocateObjectsFromPerm(oldObjectPerm);
  487.             event->IToolboxEvent(NULL, theEventRecord);
  488.             event->fClickCount = gDispatcher->fClickCount;
  489.             event->fAffectsMenus = FALSE;
  490.             
  491.             if (!HandleMouseDown(hitPt, event, gStdHysteresis))
  492.             {
  493.                 // NOTE: for backwards compatibility with MacApp 2.0 - override your
  494.                 // TMenuView subclass' HandleMouseDown method to return false, and all
  495.                 // should work as before
  496.  
  497.                 newItem = this->FindItem(hitPt);
  498.                 this->UpdateHighlight(whichItem, newItem);// Update highlighting 
  499.             }
  500.             event = (TToolboxEvent *)FreeIfObject(event);
  501.         }
  502.     }
  503.     else
  504.         this->UpdateHighlight(whichItem, newItem);    // Update highlighting 
  505.  
  506.     gTrackingInMenu = saveTrackingInMenu;
  507.  
  508.     // Tell MenuManager about new item 
  509.     whichItem = newItem;
  510. } // TMenuView::HandleChooseMessage 
  511.  
  512. //----------------------------------------------------------------------------------------
  513. // TMenuView::HandleDrawMessage: 
  514. //----------------------------------------------------------------------------------------
  515. #pragma segment MAMenuRes
  516.  
  517. void TMenuView::HandleDrawMessage(short /* message */,
  518.                                          MenuRef /* theMenu */,
  519.                                          CRect& /* menuRect */,
  520.                                          CPoint /* hitPt */,
  521.                                          short& /* whichItem */)
  522.  
  523. {
  524.     this->DrawContents();
  525.     fHighlighted = FALSE;
  526.     if (!IsEnabled())
  527.     {
  528.         PenPat(&qd.gray);
  529.         PenMode(notSrcBic);
  530.         PaintRect(&this->GetQDExtent());
  531.     }
  532. } // TMenuView::HandleDrawMessage 
  533.  
  534. //----------------------------------------------------------------------------------------
  535. // TMenuView::HandleSizeMessage: 
  536. //----------------------------------------------------------------------------------------
  537. #pragma segment MAMenuRes
  538.  
  539. void TMenuView::HandleSizeMessage(short /* message */,
  540.                                          MenuRef theMenu,
  541.                                          CRect& /* menuRect */,
  542.                                          CPoint /* hitPt */,
  543.                                          short& /* whichItem */)
  544.  
  545. {
  546.     VRect vr(this->GetFrame());
  547.     this->ComputeFrame(vr);
  548.     (*theMenu)->menuWidth = (short)vr.GetLength(hSel);
  549.     (*theMenu)->menuHeight = (short)vr.GetLength(vSel);
  550. } // TMenuView::HandleSizeMessage 
  551.  
  552. //----------------------------------------------------------------------------------------
  553. // TMenuView::HandlePopUpMessage: 
  554. //----------------------------------------------------------------------------------------
  555. #pragma segment MAMenuRes
  556.  
  557. void TMenuView::HandlePopUpMessage(short /* message */,
  558.                                           MenuRef /* theMenu */,
  559.                                           CRect& menuRect,
  560.                                           CPoint hitPt,
  561.                                           short& /* whichItem */)
  562.  
  563. {
  564.     VRect vr(this->GetExtent());
  565.     this->ComputeFrame(vr);
  566.     menuRect = this->ViewToQDRect(vr) + hitPt;
  567. } // TMenuView::HandlePopUpMessage 
  568.  
  569. //----------------------------------------------------------------------------------------
  570. // TMenuView::Highlight: 
  571. //----------------------------------------------------------------------------------------
  572. #pragma segment MAMenuRes
  573.  
  574. void TMenuView::Highlight(short,
  575.                                  Boolean)
  576.  
  577. {
  578.     this->SubClassResponsibility();
  579. } // TMenuView::Highlight 
  580.  
  581. //----------------------------------------------------------------------------------------
  582. // TMenuView::IsItemEnabled: 
  583. //----------------------------------------------------------------------------------------
  584. #pragma segment MAMenuRes
  585. Boolean TMenuView::IsItemEnabled(short item)
  586.  
  587. {
  588.     return (*fMenuRef)->enableFlags & (1 << item);
  589. } // TMenuView::IsItemEnabled 
  590.  
  591. //----------------------------------------------------------------------------------------
  592. // TMenuView::GetMenuViewColors: 
  593. //----------------------------------------------------------------------------------------
  594. #pragma segment MAMenuRes
  595.  
  596. void TMenuView::GetMenuViewColors(ResNumber theMenu,
  597.                                          short theItem,
  598.                                          MenuColors& theMenuColors)
  599.  
  600. {
  601.     enum TypeOfMenuInfo { aMenuItem, aMenuTitle, aMenuBar, noType };
  602.  
  603.  
  604.     MCEntryPtr aMCEntryPtr;
  605.     TypeOfMenuInfo typeOfRequest;
  606.     TypeOfMenuInfo typeOfEntryFound;
  607.     ResNumber theEntryMenu = theMenu;
  608.     short theEntryItem = theItem;
  609.  
  610.     if (qNeedsColorQD || HasColorQD())
  611.     {
  612.         if (theItem)
  613.             typeOfRequest = aMenuItem;
  614.         else if (theMenu)
  615.             typeOfRequest = aMenuTitle;
  616.         else
  617.             typeOfRequest = aMenuBar;
  618.  
  619.         aMCEntryPtr = GetMCEntry(theEntryMenu, theEntryItem);
  620.         if (aMCEntryPtr == NULL)                // not found, try as title 
  621.         {
  622.             theEntryItem = 0;
  623.             aMCEntryPtr = GetMCEntry(theEntryMenu, theEntryItem);
  624.             if (aMCEntryPtr == NULL)            // not found, try as menubar 
  625.             {
  626.                 theEntryMenu = 0;
  627.                 aMCEntryPtr = GetMCEntry(theEntryMenu, theEntryItem);
  628.             }
  629.         }
  630.  
  631.         if (aMCEntryPtr == NULL)
  632.             typeOfEntryFound = noType;
  633.         else
  634.         {
  635.             if (theEntryItem)
  636.                 typeOfEntryFound = aMenuItem;
  637.             else if (theEntryMenu)
  638.                 typeOfEntryFound = aMenuTitle;
  639.             else
  640.                 typeOfEntryFound = aMenuBar;
  641.         }
  642.  
  643.         switch (typeOfEntryFound)
  644.         {
  645.             case aMenuItem:
  646.                 theMenuColors.itemColor = (*aMCEntryPtr).mctRGB1;
  647.                 theMenuColors.backgroundColor = (*aMCEntryPtr).mctRGB4;
  648.                 theMenuColors.markColor = (*aMCEntryPtr).mctRGB1;
  649.                 theMenuColors.commandColor = (*aMCEntryPtr).mctRGB1;
  650.                 break;
  651.                     
  652.             case aMenuTitle:
  653.                 switch (typeOfRequest)
  654.                 {
  655.                     case aMenuItem:
  656.                         {
  657.                             theMenuColors.itemColor = (*aMCEntryPtr).mctRGB3;
  658.                             theMenuColors.backgroundColor = (*aMCEntryPtr).mctRGB4;
  659.                             theMenuColors.markColor = (*aMCEntryPtr).mctRGB3;
  660.                             theMenuColors.commandColor = (*aMCEntryPtr).mctRGB3;
  661.                             break;
  662.                         }
  663.                     case aMenuTitle:
  664.                         {
  665.                             theMenuColors.itemColor = (*aMCEntryPtr).mctRGB1;
  666.                             theMenuColors.backgroundColor = (*aMCEntryPtr).mctRGB2;
  667.                             theMenuColors.markColor = (*aMCEntryPtr).mctRGB1;
  668.                             theMenuColors.commandColor = (*aMCEntryPtr).mctRGB1;
  669.                             break;
  670.                         }
  671.                 }
  672.                 break;
  673.                 
  674.             case aMenuBar:
  675.                 switch (typeOfRequest)
  676.                 {
  677.                     case aMenuItem:
  678.                         theMenuColors.itemColor = (*aMCEntryPtr).mctRGB3;
  679.                         theMenuColors.backgroundColor = (*aMCEntryPtr).mctRGB2;
  680.                         theMenuColors.markColor = (*aMCEntryPtr).mctRGB3;
  681.                         theMenuColors.commandColor = (*aMCEntryPtr).mctRGB3;
  682.                         break;
  683.                         
  684.                     case aMenuTitle:
  685.                         theMenuColors.itemColor = (*aMCEntryPtr).mctRGB1;
  686.                         theMenuColors.backgroundColor = (*aMCEntryPtr).mctRGB4;
  687.                         theMenuColors.markColor = (*aMCEntryPtr).mctRGB1;
  688.                         theMenuColors.commandColor = (*aMCEntryPtr).mctRGB1;
  689.                         break;
  690.                         
  691.                     case aMenuBar:
  692.                         theMenuColors.itemColor = (*aMCEntryPtr).mctRGB1;
  693.                         theMenuColors.backgroundColor = (*aMCEntryPtr).mctRGB4;
  694.                         theMenuColors.markColor = (*aMCEntryPtr).mctRGB1;
  695.                         theMenuColors.commandColor = (*aMCEntryPtr).mctRGB1;
  696.                         break;
  697.  
  698.                     case noType:
  699.                         break;
  700.                 }
  701.                 break;
  702.                 
  703.             case noType:
  704.                 theMenuColors.itemColor = gRGBBlack;
  705.                 theMenuColors.backgroundColor = gRGBWhite;
  706.                 theMenuColors.markColor = gRGBBlack;
  707.                 theMenuColors.commandColor = gRGBBlack;
  708.                 break;
  709.         }
  710.     }
  711.     else
  712.     {
  713.         theMenuColors.itemColor = gRGBBlack;
  714.         theMenuColors.backgroundColor = gRGBWhite;
  715.         theMenuColors.markColor = gRGBBlack;
  716.         theMenuColors.commandColor = gRGBBlack;
  717.     }
  718. } // TMenuView::GetMenuViewColors 
  719.  
  720. //----------------------------------------------------------------------------------------
  721. // TMenuView::UpdateHighlight: 
  722. //----------------------------------------------------------------------------------------
  723. #pragma segment MAMenuRes
  724.  
  725. void TMenuView::UpdateHighlight(short oldItem,
  726.                                        short newItem)
  727.  
  728. {
  729.     // Update highlighting 
  730.     if (newItem == oldItem)
  731.     {
  732.         if (fFlashInterval >= 0)
  733.             if (TickCount() > fNextFlash)
  734.             {
  735.                 fHighlighted =!fHighlighted;
  736.                 this->Highlight(oldItem, fHighlighted);
  737.                 fNextFlash = Future(fFlashInterval);
  738.             }
  739.     }
  740.     else
  741.     {
  742.         if (fHighlighted)
  743.             if (oldItem != kNoMenuItem)
  744.                 this->Highlight(oldItem, FALSE);
  745.  
  746.         fHighlighted = (newItem != kNoMenuItem);
  747.         if (fHighlighted)
  748.             this->Highlight(newItem, TRUE);
  749.  
  750.         if (fFlashInterval >= 0)
  751.             fNextFlash = Future(fFlashInterval);
  752.     }
  753. } // TMenuView::UpdateHighlight 
  754.  
  755. //----------------------------------------------------------------------------------------
  756. // TMenuView::Focus: 
  757. //----------------------------------------------------------------------------------------
  758. #pragma segment MAMenuRes
  759.  
  760. Boolean TMenuView::Focus()            // override 
  761.  
  762. {
  763.     VPoint vorigin;
  764.     MenuColors theMenuColors;
  765.  
  766.     if (Inherited::Focus())
  767.     {
  768.         // Try to make the best match for the menu colors without requiring programmer
  769.         // intervention. by setting the color environment to be for items.
  770.  
  771.         this->GetMenuViewColors((*fMenuRef)->menuID, 1, theMenuColors);
  772.         SetIfColor(theMenuColors.itemColor);
  773.         SetIfBkColor(theMenuColors.backgroundColor);
  774.         return TRUE;
  775.     }
  776.     else
  777.         return FALSE;
  778. } // TMenuView::Focus 
  779.  
  780. //----------------------------------------------------------------------------------------
  781. // TMenuView::IsShown: 
  782. //----------------------------------------------------------------------------------------
  783. #pragma segment MAMenuRes
  784.  
  785. Boolean TMenuView::IsShown()
  786. {
  787.     // Menu views do not always have superviews...
  788.     if( fSuperView == NULL )
  789.         return fShown;
  790.     else
  791.         return Inherited::IsShown();
  792. } // TMenuView::IsShown 
  793.  
  794. //----------------------------------------------------------------------------------------
  795. // TMenuView::IsActive: 
  796. //----------------------------------------------------------------------------------------
  797. #pragma segment MAMenuRes
  798.  
  799. Boolean TMenuView::IsActive()            // override 
  800. {
  801.     return TRUE;                                // if we are asking then we are active
  802. } // TMenuView::IsActive 
  803.  
  804. //----------------------------------------------------------------------------------------
  805. // TMenuView::FocusOnSuperView: 
  806. //----------------------------------------------------------------------------------------
  807. #pragma segment MAMenuRes
  808.  
  809. Boolean TMenuView::FocusOnSuperView()// override 
  810.  
  811. {
  812.     SetPort((GrafPtr) & pMenuCPort);
  813.     
  814.     CPoint qdOrigin(this->GetQDOrigin());
  815.     SetOrigin(qdOrigin.h, qdOrigin.v);
  816.  
  817.     ClipRect(&(qd.thePort->portRect));
  818.  
  819.     return TRUE;
  820. } // TMenuView::FocusOnSuperView 
  821.  
  822. //----------------------------------------------------------------------------------------
  823. // TMenuView::GetGrafPort: 
  824. //----------------------------------------------------------------------------------------
  825. #pragma segment MAMenuRes
  826.  
  827. GrafPtr TMenuView::GetGrafPort()        // override 
  828.  
  829. {
  830.     return (GrafPtr) & pMenuCPort;
  831. } // TMenuView::GetGrafPort 
  832.  
  833. //----------------------------------------------------------------------------------------
  834. // End of UMenuView.cp
  835.  
  836. #pragma segment Inline
  837.